package com.shangxia.basic.common.mybatis.dynamicsource;

import com.github.pagehelper.PageInterceptor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.util.Properties;

/**
 * @ProjectName: MyDemo_zy
 * @ClassName: ResourceType
 * @Time: 2020-04-01 19:55
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResourceType {
    private String key;
    private String type;
    private String driver;
    private String dialect;
    private PageInterceptor pageHelper = new PageInterceptor();

    ResourceType(String key) {
        setKey(key);
    }

    public void setDriver(String driver) {
        this.driver = driver;
        switch (driver) {
            case "oracle.jdbc.driver.OracleDriver":
                this.type = "oracle";
                this.dialect = "com.github.pagehelper.dialect.helper.OracleDialect";
                break;
            case "com.mysql.cj.jdbc.Driver":
                this.type = "mysql";
                this.dialect = "com.github.pagehelper.dialect.helper.MySqlDialect";
                break;
            case "org.postgresql.Driver":
                this.type = "postgresql";
                this.dialect = "com.github.pagehelper.dialect.helper.HsqldbDialect";
                break;
            default:
                this.type = "";
                this.dialect = "com.github.pagehelper.PageHelper";
        }
        Properties p = new Properties();
        if (!StringUtils.isEmpty(this.type)) {
            p.setProperty("dialect", "com.github.pagehelper.PageHelper");
            p.setProperty("helperDialect", this.dialect);
        }
        pageHelper.setProperties(p);
    }

    private void setPageHelper() {
    }
}
